package com.simp.controller;

import com.simp.aop.SysLog;
import com.simp.dto.SysThemeDto;
import com.simp.entity.SysThemeEntity;
import com.simp.model.SysThemeModel;
import com.simp.page.PageVO;
import com.simp.page.R;
import com.simp.page.SuperController;
import com.simp.service.SysThemeService;
import com.simp.utils.BeanConvertUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author pan.shun
 * @since 2022/3/15 11:17
 */
@Api(tags = "系统主题")
@RestController
@RequestMapping("/theme")
public class SysThemeController extends SuperController {

    @Autowired
    private SysThemeService sysThemeService;

    @ApiOperation(value = "获取当前用户主题", notes = "通过用户的token获取主题", httpMethod = "GET")
    @GetMapping("/getUserTheme")
    public R getThemeByUserId(HttpServletRequest request) {
        return sysThemeService.getThemeByUserId(request);
    }

    @SysLog(value = "用户主题", addOrUpdate = true)
    @ApiOperation(value = "主题新增和修改", notes = "主题新增和修改", httpMethod = "POST")
    @PostMapping("/addOrUpdateTheme")
    public R addOrUpdateTheme(@RequestBody SysThemeModel sysTheme) {
        SysThemeEntity convert = BeanConvertUtils.convert(sysTheme, SysThemeEntity.class);
        return sysThemeService.addOrUpdateTheme(convert);
    }

    @ApiOperation(value = "获取主题下拉列表", notes = "获取主题下拉列表", httpMethod = "GET")
    @GetMapping("/getThemeSelectList")
    public R getThemeList() {
        return sysThemeService.getThemeList();
    }

    @ApiOperation(value = "通过主题ID获取主题", notes = "通过主题ID获取主题", httpMethod = "GET")
    @GetMapping("/getThemeById/{id}")
    public R getThemeById(@ApiParam(name = "id", value = "主题ID", required = true) @PathVariable String id) {
        return sysThemeService.getThemeById(id);
    }

    @ApiOperation(value = "主题分页查询", notes = "主题分页查询 ，条件为 > name= ,其中name是主题名称", httpMethod = "GET")
    @GetMapping("/getThemePageList")
    public R getThemePageList(HttpServletRequest request, SysThemeDto sysThemeDto) {
        PageVO<SysThemeEntity> themePageList = sysThemeService.getThemePageList(request, sysThemeDto);
        return R.success(themePageList);
    }

    @SysLog(value = "默认主题设置")
    @ApiOperation(value = "将当前主题设置为用户的默认主题")
    @GetMapping("/updateCurrentUserTheme/{themeId}")
    public R updateCurrentUserTheme(
            @ApiParam(name = "主题ID", value = "themId", required = true)
            @PathVariable String themeId, HttpServletRequest request) {
        return sysThemeService.updateCurrentUserTheme(request, themeId);
    }

    @SysLog(value = "系统主题删除")
    @ApiOperation(value = "通过主题id删除主题")
    @GetMapping("/removeThemeById/{id}")
    public R removeThemeById(@PathVariable String id) {
        return sysThemeService.removeThemeById(id);
    }
}
